package vn.student.mylib;

import vn.student.R;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.DatePicker;

public class DateDateDialog implements android.content.DialogInterface.OnClickListener {
	public static void viewDialog(String title, String[] dateStart, String[] dateEnd, Context ctx,android.content.DialogInterface.OnClickListener onClickListener){
		 
		LayoutInflater li = LayoutInflater.from(ctx); 
		View view = li.inflate(R.layout.date_date_dialog, null); 
		
		if(dateStart!=null&&dateStart.length==3){
			DatePicker tmp = ((DatePicker) view.findViewById(R.id.dateStartPicker));
			tmp.updateDate(Integer.valueOf(dateStart[0]), Integer.valueOf(dateStart[1])-1, Integer.valueOf(dateStart[2]));
		}
		if(dateEnd!=null&&dateStart.length==3){
			DatePicker tmp = ((DatePicker) view.findViewById(R.id.dateEndPicker));
			tmp.updateDate(Integer.valueOf(dateEnd[0]), Integer.valueOf(dateEnd[1])-1, Integer.valueOf(dateEnd[2]));
		}
		AlertDialog.Builder builder = new AlertDialog.Builder(ctx); 
		builder.setTitle(title); 
		builder.setView(view); 
		  
		builder.setPositiveButton("OK", onClickListener);
		builder.setNegativeButton("Cancel",  new DateDateDialog()); 
		
		//get the dialog 
		AlertDialog ad = builder.create(); 
		
		ad.show(); 
	}
	@Override
	public void onClick(DialogInterface dialog, int which) {
		// Do notthing.
	}
}
